<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //  递归: 函数自己调用自己
    // function fn() {
    //     fn()
    // }
    // fn()
</script>
<script>
    // 递归深拷贝
    var obj = {
        name:'小明',
        age:18,
        object : {
        name:'小米',
        age:10
        },
        arr:[1,2,3]
    }
    var newobj = {}
    function fn(obj , newobj) {
        for(key in obj) {
            if(obj[key].constructor == Object){
                newobj[key] ={}
                fn(obj[key],newobj[key])
            }else if(obj[key].constructor == Array){
                newobj[key] =[]
                fn(obj[key],newobj[key])
            }else{
                newobj[key] = obj[key]
            }
        }
    }
    fn(obj,newobj)
    console.log(newobj);
    
    // 对象深拷贝
    // for in
    // JSON
    // Object.assign()
    // 扩展运算符深拷贝
</script>
</html>